import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

import { AddComponent } from './components/add/add.component';
import { DetailsComponent } from './components/details/details.component';
import { HistoryListComponent, RunningListComponent, ScheduleListComponent } from './components/list/list.component';
import { TaskComponent } from './components/task/task.component';
import { DetailsService } from './services/details.service';
import { ListService } from './services/list.service';
import { ZoneListService } from '../log/services/zone-list.service';

const routes: Routes = [
	{
		path: '',
		data: { title: '任务管理' },
		children: [
			{ path: '', pathMatch: 'full', redirectTo: 'running' },
			{
				path: 'add',
				component: AddComponent,
				data: { title: '添加任务' },
			},
			{
				path: ':category/detail/:name',
				component: DetailsComponent,
				runGuardsAndResolvers: 'always',
				resolve: {
					details: DetailsService,
				},
				data: { title: '任务详情' },
			},
			{
				path: '',
				component: TaskComponent,
				children: [
					{
						path: 'running',
						data: { title: '执行中' },
						component: RunningListComponent,
						runGuardsAndResolvers: 'always',
						resolve: {
							list: ListService,
							zone_list: ZoneListService
						},
					},
					{
						path: 'schedule',
						data: { title: '周期任务' },
						component: ScheduleListComponent,
						runGuardsAndResolvers: 'always',
						resolve: {
							list: ListService,
							zone_list: ZoneListService
						},
					},
					{
						path: 'history',
						data: { title: '历史任务' },
						component: HistoryListComponent,
						runGuardsAndResolvers: 'always',
						resolve: {
							list: ListService,
							zone_list: ZoneListService
						},
					},
				],
			},
		],
	},
];
@NgModule({
	imports: [RouterModule.forChild(routes)],
	exports: [RouterModule],
})
export class TaskRoutingModule {}
